package com.mmlc.meimei.lichengkongjian.classify;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.requestbean.BaseResponseBean;
import com.androidnetframe.responsejavabean.RequestError;
import com.androidnetframe.utils.LogUtils;
import com.easemob.helpdeskdemo.Constant;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.DefaultHandler;
import com.mmlc.businessutils.MyShareUtils;
import com.mmlc.inter.InterActivity;
import com.mmlc.meimei.lichengkongjian.App;
import com.mmlc.meimei.lichengkongjian.MainActivity;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.meimei.lichengkongjian.WDActivity;
import com.mmlc.meimei.lichengkongjian.WPActivity;
import com.mmlc.meimei.lichengkongjian.customview.BanViewPager;
import com.mmlc.meimei.lichengkongjian.home.WebViewActivity;
import com.mmlc.meimei.lichengkongjian.mine.LoginActivity;
import com.mmlc.network.filter.ApplyShelfRequestFilter;
import com.mmlc.network.filter.GoodsCollectRequestFilter;
import com.mmlc.network.filter.GoodsDetailRequestFilter;
import com.mmlc.network.filter.IOrderRequestFilter;
import com.mmlc.network.filter.JoinCartRequestFilter;
import com.mmlc.network.filter.WoyaoshiRequestFilter;
import com.mmlc.network.responsebean.GoodsDetailBaseResponseBean;
import com.mmlc.network.responsebean.GoodsDetailResponseBean;
import com.mmlc.utils.Constants;
import com.mmlc.utils.GoodsDetailUtils;
import com.mmlc.utils.ToastUtils;
import com.mmlc.utils.ViewUtils;
import com.mmlc.utils.WebUtils;
import com.mmlc.utils.XUtils;
import com.mmlc.widget.ViewInfoBannerPager;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.utils.Log;

import org.xutils.common.Callback;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import static com.mmlc.utils.ViewUtils.getView;


public class ProductInfoActivity extends InterActivity {

    @Override
    protected int initContentView() {
        return R.layout.activity_productdetail;
    }

    String goods_id, scan, gdid;
    DisplayMetrics metrics;

    @Override
    protected void initExtra() {
        super.initExtra();
        goods_id = getIntent().getStringExtra("goods_id");
        scan = getIntent().getStringExtra("scan");
        metrics = getResources().getDisplayMetrics();
    }

    ViewInfoBannerPager info_banner;
    /**
     * 购物袋数量
     */
//    SlideDetailsLayout sv_switch;
    TextView tv_bag_count, caizhi, chandi;
    ImageView iv_like, iv_introduce, iv_mark;
    TextView tv_sub, tv_name, tv_price, tv_market_price, tv_originalPrice, tv_introduce, tv_code;
    LinearLayout ll_size, ll_show, ll_replace, ll_buy;
    WebView dialog_web_size;
    RelativeLayout physicalStoreRl;
    LinearLayout layout_error, ll_discount;
    RelativeLayout rl_title, rl_nav_bottom, rl_time;
    CoordinatorLayout cdl_content;
    TextView tv_info, tv_scan, tv_titletype, tv_price_count, tv_introdetail;
    ImageView iv_infonext;
    List<Fragment> fragmentList;
    List<String> mTitleList;
    FastGoodsDetailFragment fragment;
    TextView tvDay, tvHour, tvMinute, tvSecond, textView1, textView2,textView3;
    LinearLayout ll_promise;
    LinearLayout ll_selector_content;
    RelativeLayout rootView;
    BridgeWebView webView;

    @Override
    protected void initView() {
        textView1 = getView(activity, R.id.textview1);
        webView = getView(activity, R.id.webview);
        tv_buy = getView(activity, R.id.tv_buy);
        webView.setDefaultHandler(new DefaultHandler());
        webView.getSettings().setJavaScriptEnabled(true);//是否允许执行js，默认为false。设置true时，会提醒可能造成XSS漏洞
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口，如window.open()，默认为false
        webView.setWebChromeClient(new WebChromeClient());
        webView.getSettings().setSupportZoom(true);//是否可以缩放，默认true
        webView.getSettings().setDisplayZoomControls(true);
//        webView.getSettings().setBuiltInZoomControls(true);//是否显示缩放按钮，默认false
        webView.getSettings().setUseWideViewPort(true);//设置此属性，可任意比例缩放。大视图模  式
        webView.getSettings().setUserAgentString(webView.getSettings().getUserAgentString() + "mmlc.meiqi");
        webView.getSettings().setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        webView.getSettings().setAppCacheEnabled(true);//是否使用缓存
        webView.getSettings().setAppCachePath(Constants.DIR_CACHE);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setDatabaseEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);//DOM Storage
//        webView.requestFocus();
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        caizhi = getView(activity, R.id.caizhi);
        chandi = getView(activity, R.id.chandi);
        ll_selector_content = getView(activity, R.id.ll_selector_content);
        textView2 = getView(activity, R.id.textview2);
        textView3 = getView(activity, R.id.textview3);
        layout_error = getView(activity, R.id.layout_error);
        rootView = getView(activity, R.id.rootView);
        rl_title = getView(activity, R.id.rl_title);
        rl_nav_bottom = getView(activity, R.id.rl_nav_bottom);
        cdl_content = getView(activity, R.id.cdl_content);
        tv_info = getView(activity, R.id.tv_info);
        tv_scan = getView(activity, R.id.tv_scan);
        tv_titletype = getView(activity, R.id.tv_titletype);
        iv_mark = getView(activity, R.id.iv_mark);
        tv_bag_count = getView(activity, R.id.tv_bag_count);
        iv_like = getView(activity, R.id.iv_like);
        tv_code = getView(activity, R.id.tv_code);
        info_banner = getView(this, R.id.info_banner);
        physicalStoreRl = getView(this, R.id.physical_store_rl);
        tv_name = getView(activity, R.id.tv_name);
        tv_sub = getView(activity, R.id.tv_sub);
        tv_price = getView(activity, R.id.tv_price);
        tv_price_count = getView(activity, R.id.tv_price_count);
        tv_originalPrice = getView(activity, R.id.tv_originalPrice);
        iv_infonext = getView(activity, R.id.iv_infonext);
        tv_introdetail = getView(activity, R.id.tv_introdetail);
        tv_market_price = getView(activity, R.id.tv_market_price);
        ViewUtils.getView(activity, R.id.ll_pull_up).setOnClickListener(this);
        iv_introduce = getView(activity, R.id.iv_introduce);
        tv_introduce = (TextView) findViewById(R.id.tv_introduce);
//        sv_switch = getView(activity, R.id.sv_switch);
        ll_size = getView(activity, R.id.ll_size);
        ll_show = getView(activity, R.id.ll_show);
        ll_replace = getView(activity, R.id.ll_replace);
        ll_buy = getView(activity, R.id.ll_nav_bottom);
        rl_time = getView(activity, R.id.rl_time);
        tvDay = getView(activity, R.id.tv_day);
        tvHour = getView(activity, R.id.tv_hour);
        tvMinute = getView(activity, R.id.tv_minute);
        tvSecond = getView(activity, R.id.tv_second);
        ll_promise = getView(activity, R.id.ll_promise);
        ll_discount = getView(activity, R.id.ll_discount);
        type = getIntent().getStringExtra("type");
        if (!TextUtils.isEmpty(type) && type.equals("replace")) {
            ll_buy.setVisibility(View.GONE);
            ll_replace.setVisibility(View.VISIBLE);
        }

        initClick();
    }

    String type;
    boolean market;

    public void initClick() {
        getView(activity, R.id.iv_errorback).setOnClickListener(this);
        getView(activity, R.id.tv_errorback).setOnClickListener(this);
        getView(activity, R.id.iv_back).setOnClickListener(this);
        getView(activity, R.id.iv_share).setOnClickListener(this);
        getView(activity, R.id.iv_like).setOnClickListener(this);
        getView(activity, R.id.rl_shopping_bag).setOnClickListener(this);
        getView(activity, R.id.iv_service).setOnClickListener(this);

        getView(activity, R.id.tv_add).setOnClickListener(this);
        getView(activity, R.id.tv_buy).setOnClickListener(this);
        getView(activity, R.id.tv_replace).setOnClickListener(this);
        getView(activity, R.id.physical_store_rl).setOnClickListener(this);
        getView(activity, R.id.tv_info).setOnClickListener(this);
        getView(activity, R.id.ll_introdetail).setOnClickListener(this);
        getView(activity, R.id.tv_scan).setOnClickListener(this);
        getView(activity, R.id.woshi).setOnClickListener(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
//        scv_home.smoothScrollTo(0, 0);
    }

    int navIndex = -1;
    String enddate = "-1", startdate = "-1";
    List<GoodsDetailResponseBean.DataBean.TipsBean> tips;
    GoodsDetailResponseBean.DataBean data;

    @Override
    protected void initInfo() {
        GoodsDetailRequestFilter filter = new GoodsDetailRequestFilter(activity);
        String type = getIntent().getStringExtra("type");

        if (!TextUtils.isEmpty(type) && type.equals("replace")) {
            filter.requestBean.goods_id = getIntent().getStringExtra("long_id");
        } else if (!TextUtils.isEmpty(type) && type.equals("sku")) {
            filter.requestBean.sku = getIntent().getStringExtra("sku");
        } else {
            filter.requestBean.goods_id = goods_id;
        }
        filter.offerErrorParams(rootView);
        filter.isTransparence = true;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<GoodsDetailResponseBean>() {
            @Override
            public void onSuccess(GoodsDetailResponseBean result) {
                if (result != null) {
                    tips = new ArrayList<>();
                    tips = result.getData().getTips();
                    data = result.getData();
                    initPromise();
                    if (result.getCode() == 0) {
                        if (!TextUtils.isEmpty(scan) && scan.equals("scan")) {
                            tv_titletype.setText("码上购");
                        } else {
                            tv_titletype.setText("详情");
                        }
                        enddate = result.getData().getEvent_end_date() + "";
                        startdate = result.getData().getEvent_start_date() + "";
                        rl_title.setVisibility(View.VISIBLE);
                        cdl_content.setVisibility(View.VISIBLE);
                        rl_nav_bottom.setVisibility(View.VISIBLE);
                        goodsDetail = result;
                        GoodsDetailUtils goodsDetailUtils = new GoodsDetailUtils(ProductInfoActivity.this);
                        goodsDetailUtils.reloadDatas(ProductInfoActivity.this, goodsDetail, ll_selector_content, null);
                        webView.loadUrl(result.getData().getTab_info().get(0).getUrl());
                        webViewClick();
                        caizhi.setText(goodsDetail.getData().getGoods_param().get(0).getValue());
                        chandi.setText(goodsDetail.getData().getGoods_param().get(1).getValue());
                        setCountdownTime();
                        displayintro(result);
                        initViewPager(result);
                        getGoodsDetailBase(result.getData());
                        displayGoodsDetail(result.getData());
                        textView1.setText("发售时间:" );
                        textView3.setText(result.getData().getSale_date());
                        seconds2 = result.getData().getSale_seconds();
                        setDownTime();
                    } else if (result.getCode() == 10000) {
                        if (!TextUtils.isEmpty(scan) && scan.equals("scan")) {
                            tv_titletype.setText("码上购");
                        } else {
                            tv_titletype.setText("详情");
                        }
                        goodsDetail = result;
                        rl_title.setVisibility(View.VISIBLE);
                        tv_info.setVisibility(View.VISIBLE);
                        gdid = result.getData().getId() + "";
                        market = true;
                        cdl_content.setVisibility(View.VISIBLE);
                        enddate = result.getData().getEvent_end_date() + "";
                        startdate = result.getData().getEvent_start_date() + "";
                        if (App.user.getUserType() == 0) {
                            tv_scan.setText("返回");
                        } else {
                            tv_scan.setText("申请上架");
                        }
                        tv_scan.setVisibility(View.VISIBLE);
                        cdl_content.setVisibility(View.VISIBLE);
                        setCountdownTime();
                        displayintro(result);
                        initViewPager(result);
                        getGoodsDetailBase(result.getData());
                        displayGoodsDetail(result.getData());
                        ll_discount.setVisibility(View.GONE);
                        tv_market_price.setVisibility(View.GONE);
                        tv_price.setText("价格：待定");
                        tv_price.setTextSize(16);
                        tv_originalPrice.setVisibility(View.GONE);
                    }


                } else {
                    LogUtils.e("ProductInfoActivity", "解析错误");
                    return;
                }
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                getView(ProductInfoActivity.this, R.id.rl_nav_bottom).setVisibility(View.GONE);
                getView(ProductInfoActivity.this, R.id.physical_store_rl).setClickable(false);
                if (!TextUtils.isEmpty(scan) && scan.equals("scan")) {
                    if (serverError.errCode.equals("2")) {
                        layout_error.setVisibility(View.VISIBLE);
                    }
                } else {
                    ToastUtils.showToast(serverError.mess);
                }

            }
        });
    }

    private void webViewClick() {
        WebUtils.setWebJS(webView,this,null);
    }

    int flag = 1;

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_info:
                tv_info.setVisibility(View.GONE);
                break;
            case R.id.iv_errorback:
                finish();
                break;
            case R.id.tv_errorback:
                finish();
                break;
            case R.id.iv_back:
                finish();
                break;
            case R.id.ll_introdetail:
                if (!TextUtils.isEmpty(brand_url)) {
                    Intent intent = new Intent(ProductInfoActivity.this, WebViewActivity.class);
                    intent.putExtra("title", "品牌详情");
                    intent.putExtra("url", brand_url);
                    startActivity(intent);
                }
                break;
            case R.id.tv_scan:
                if (tv_scan.getText().equals("返回")) {
                    finish();
                    break;
                } else if (tv_scan.getText().equals("申请上架")) {
                    //申请上架
                    applySale();
                }
                break;
            case R.id.iv_share:
                initShare();
                break;
            case R.id.iv_like:
                /** collection */
                if (App.user != null && !App.user.getLoginState()) {
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.putExtra("type", "like");
                    startActivity(intent);
                    return;
                }
                goodsCollect();
                break;
            case R.id.rl_shopping_bag:
                /** to shopping bag */
                Intent mIntent2 = new Intent(this, MainActivity.class);
                mIntent2.putExtra("flag", 4);
                startActivity(mIntent2);
                break;
            case R.id.iv_service:
                /** start conversation to service */
                if (App.user != null && !App.user.getLoginState()) {
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.putExtra("type", "service");
                    startActivity(intent);
                    return;
                }
                startActivity(new Intent(this, com.easemob.helpdeskdemo.ui.LoginActivity.class).putExtra(Constant.MESSAGE_TO_INTENT_EXTRA,
                        Constant.MESSAGE_TO_PRE_SALES));
//                Intent intent = new Intent();
////                intent.putExtra(Constant.INTENT_CODE_IMG_SELECTED_KEY, index);
//                intent.putExtra(Constant.MESSAGE_TO_INTENT_EXTRA, Constant.MESSAGE_TO_AFTER_SALES);
//                intent.setClass(this, com.easemob.helpdeskdemo.ui.LoginActivity.class);
//                startActivity(intent);
                break;
            case R.id.tv_add://我订
                flag = 1;
                navIndex = 0;
                initDialog(flag);
                break;
            case R.id.woshi://我试
                flag = 4;
                navIndex = 0;
                initDialog(flag);
                break;
            case R.id.tv_buy://我拍
                if (App.user != null && !App.user.getLoginState()) {
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.putExtra("type", "pay");
                    startActivity(intent);
                    return;
                }
                flag = 2;
                navIndex = 1;
                initDialog(flag);
                break;
            case R.id.tv_replace:
                if (App.user != null && !App.user.getLoginState()) {
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.putExtra("type", "replace");
                    startActivity(intent);
                    return;
                }
                navIndex = 0;
                initDialog(3);
                break;

            case R.id.iv_cancel:
                buyDialog.hide();
                break;
            case R.id.iv_minus:
                if (count > 1) {
                    count--;
                    displayBuyCountAndPrice();
                }
                break;
            case R.id.iv_plus:
                if (count < storeCount) {
                    count++;
                    displayBuyCountAndPrice();
                }
                break;
            case R.id.physical_store_rl:
                openPhysicalStore();
                break;
            case R.id.tv_pay2://试衣间
                Intent mIntent = new Intent(this, MainActivity.class);
                mIntent.putExtra("flag", 4);
                startActivity(mIntent);
                break;
            case R.id.tv_pay://1我拍，2，我订，3其他，4，我要试

                if (TextUtils.isEmpty(goodsDetailUtils.getGoods_id()) || goodsDetailUtils.getGoods_id() == null) {
                    return;
                }
                String id = goodsDetailUtils.getGoods_id();
                String num = tv_count.getText().toString();
                String ps = editText.getText().toString();

                if (flag == 4) {//我要试
                    WoyaoshiRequestFilter wf = new WoyaoshiRequestFilter(this);
                    wf.requestBean.goods_id = id;
                    wf.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<GoodsDetailResponseBean>() {
                        @Override
                        public void onSuccess(GoodsDetailResponseBean result) {
                            if (result.getCode() == 0) {
                                Intent mIntent = new Intent(ProductInfoActivity.this, MainActivity.class);
                                mIntent.putExtra("flag", 4);
                                startActivity(mIntent);
                            } else {
                                ToastUtils.showToast(result.getMessage());
                            }

                        }

                        @Override
                        public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                            ToastUtils.showToast(serverError.mess);
                        }
                    });
                } else {
                    IOrderRequestFilter filter = new IOrderRequestFilter(this);
                    filter.requestBean.gid = id;
                    filter.requestBean.number = num;
                    if (flag == 1) {
                        filter.requestBean.method = "own";
                        if (!TextUtils.isEmpty(ps)) {
                            filter.requestBean.usize = ps;
                        } else {
                            ToastUtils.showToast("请输入尺寸");
                            return;
                        }

                    } else {
                        filter.requestBean.method = "bidding";
                        if (!TextUtils.isEmpty(ps)) {
                            filter.requestBean.price = ps;
                        } else {
                            ToastUtils.showToast("请输入拍价");
                            return;
                        }
                    }
                    filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<GoodsDetailResponseBean>() {
                        @Override
                        public void onSuccess(GoodsDetailResponseBean result) {
                            if (result.getCode() == 0) {
                                if (flag == 1) {
                                    startActivity(new Intent(context, WDActivity.class));
                                } else {
                                    startActivity(new Intent(context, WPActivity.class));
                                }
                            } else {
                                ToastUtils.showToast(result.getMessage());
                            }

                        }

                        @Override
                        public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                            ToastUtils.showToast(serverError.mess);
                        }
                    });
                }

                break;
            case R.id.ll_pull_up:
                //上拉查看图文详情
//                sv_switch.smoothOpen(true);
                break;
            case R.id.tv_complete:
                dialog_info.dismiss();
                break;

        }
    }


    public Timer timer = new Timer();
    public Timer timer2 = new Timer();
    public long time = 0;

    LinearLayout.LayoutParams params;

    public void initPromise() {
        for (int i = 0; i < tips.size(); i++) {
            params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            TextView textView = new TextView(this);
            textView.setText(tips.get(i).getName());
            textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_border_black));
            textView.setTextSize(13);
            if (i == 0) {
                params.leftMargin = 20;
            } else {
                params.leftMargin = 13;
            }
            params.topMargin = 20;
            params.bottomMargin = 20;
            ll_promise.addView(textView, params);
        }

        ll_promise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initInfoDialog();
            }
        });


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel();
        }
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
        if (null != buyDialog) {
            buyDialog.dismiss();
        }
        if (null != dialog_info) {
            dialog_info.dismiss();
        }
    }

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    int day = (int) (time / 3600L / 24L);
                    int hour = (int) ((time - day * 24L * 3600L) / 3600L);
                    int minute = (int) (time / 60L) - day * 24 * 60 - hour * 60;
                    int seconds = (int) (time - day * 24 * 3600 - hour * 3600 - minute * 60);
                    if (day < 10) {
                        tvDay.setText("0" + day);
                    } else {
                        tvDay.setText(day + "");
                    }
                    if (hour < 10) {
                        tvHour.setText("0" + hour);
                    } else {
                        tvHour.setText(hour + "");
                    }
                    if (minute < 10) {
                        tvMinute.setText("0" + minute);
                    } else {
                        tvMinute.setText(minute + "");
                    }
                    if (seconds < 10) {
                        tvSecond.setText("0" + seconds);
                    } else {
                        tvSecond.setText(seconds + "");
                    }
                    if (time <= 0) {
                        timer.cancel();
                    }
                case 2:
                    textView2.setText(formatSeconds(seconds2));
                    if (tv2 != null) {
                        tv2.setText(formatSeconds(seconds2));
                    }
                    if (seconds2 <= 0) {
                        timer2.cancel();
                        textView2.setVisibility(View.GONE);
                        if (tv2 != null)
                            tv2.setVisibility(View.GONE);
                        tv_buy.setClickable(false);
                        tv_buy.setTextColor(getResources().getColor(R.color.gray_normal));
                    }
                    break;
            }
        }
    };


    /**
     * 秒转化为天小时分秒字符串
     *
     * @param seconds
     * @return String
     */
    public static String formatSeconds(long seconds) {
        String timeStr = seconds + "秒";
        if (seconds > 60) {
            long second = seconds % 60;
            long min = seconds / 60;
            timeStr = min + "分" + second + "秒";
            if (min > 60) {
                min = (seconds / 60) % 60;
                long hour = (seconds / 60) / 60;
                timeStr = hour + "小时" + min + "分" + second + "秒";
                if (hour > 24) {
                    hour = ((seconds / 60) / 60) % 24;
                    long day = (((seconds / 60) / 60) / 24);
                    timeStr = (day < 10 ? "0" + day : day) + " 天 " + (hour < 10 ? "0" + hour : hour) + " 时 " + (min < 10 ? "0" + min : min) + " 分 " + second + " 秒 ";
                }
            }
        }
        return timeStr;
    }

    long seconds2 = 0;

    private void setDownTime() {
        if (seconds2 > 0) {
            textView3.setVisibility(View.VISIBLE);
            textView2.setTextColor(getResources().getColor(R.color.text_red));
            TimerTask task = new TimerTask() {
                @Override
                public void run() {
                    seconds2--;
                    Message message = new Message();
                    message.what = 2;
                    handler.sendMessage(message);
                }
            };
            timer2.schedule(task, 1000, 1000);
        } else {
            textView3.setVisibility(View.GONE);
            textView2.setTextColor(getResources().getColor(R.color.black));
            textView2.setText("已发售");
            if(tv_buy==null){
                tv_buy = getView(activity, R.id.tv_buy);
            }
            tv_buy.setClickable(false);
            tv_buy.setTextColor(getResources().getColor(R.color.gray_normal));
        }
    }

    // 设置倒计时
    private void setCountdownTime() {
        if (Long.parseLong(startdate) > 0) {
            //未开始
            rl_time.setVisibility(View.GONE);
        }

        if (Long.parseLong(enddate) <= 0) {
            //结束
            rl_time.setVisibility(View.GONE);

        }

        if (Long.parseLong(startdate) <= 0 && Long.parseLong(enddate) > 0) {
            rl_time.setVisibility(View.VISIBLE);
            time = Long.parseLong(enddate);

            TimerTask task = new TimerTask() {
                @Override
                public void run() {
                    time--;
                    Message message = new Message();
                    message.what = 1;
                    handler.sendMessage(message);
                }
            };
            timer.schedule(task, 1000, 1000);
        }
    }

    private void applySale() {
        if (TextUtils.isEmpty(gdid)) {
            ToastUtils.showToast("请稍后再试");
            return;
        }
        ApplyShelfRequestFilter filter = new ApplyShelfRequestFilter(activity);
        filter.requestbean.goods_id = gdid;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<BaseResponseBean>() {
            @Override
            public void onSuccess(BaseResponseBean result) {
                ToastUtils.showToast(result.getMessage() + "");
                tv_scan.setClickable(false);
                tv_scan.setText("已申请上架");
                tv_scan.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_button_press));
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                ToastUtils.showToast(serverError.mess);
            }
        });
    }

    private int nowIndex;

    private void openPhysicalStore() {
        Intent intent = new Intent(context, PhysicalStoreActivity.class);
        if (null != goodsDetail.getData().getBrand_id()) {
            intent.putExtra("id", goodsDetail.getData().getBrand_id());
            startActivity(intent);
        } else {
            ToastUtils.showToast("暂无实体店信息");
        }
    }


    UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onResult(SHARE_MEDIA share_media) {
            LogUtils.e("umShareListener", share_media.toString() + "-->分享成功");
            ToastUtils.showToast(share_media.toString());
        }

        @Override
        public void onError(SHARE_MEDIA share_media, Throwable throwable) {
            LogUtils.e("umShareListener", share_media.toString() + "-->分享失败");
            ToastUtils.showToast(share_media.toString());
        }

        @Override
        public void onCancel(SHARE_MEDIA share_media) {
            LogUtils.e("umShareListener", share_media.toString() + "-->取消分享");
            ToastUtils.showToast(share_media.toString());
        }
    };

    /**
     * 分享
     */
   /* UMSocialService mController;*/
    UMShareAPI mShareAPI = null;
    private UMAuthListener umAuthListener = new UMAuthListener() {
        @Override
        public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
            Toast.makeText(getApplicationContext(), "Authorize succeed", Toast.LENGTH_SHORT).show();
            Log.d("user info", "user info:" + data.toString());
        }

        @Override
        public void onError(SHARE_MEDIA platform, int action, Throwable t) {
            Toast.makeText(getApplicationContext(), "Authorize fail", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform, int action) {
            Toast.makeText(getApplicationContext(), "Authorize cancel", Toast.LENGTH_SHORT).show();
        }
    };

    private void initShare() {
        /*final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[]
                {
                        SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,// SHARE_MEDIA.SINA,
                        SHARE_MEDIA.QQ, SHARE_MEDIA.SINA
                };

        Config.REDIRECT_URL="http://sns.whalecloud.com/sina2/callback";
        Log.LOG = true;
        new ShareAction(this).setDisplayList(displaylist)
                .setListenerList(umShareListener)
               .withTitle(goodsDetail.getData().getGoods_name())
                .withText(goodsDetail.getData().getGoods_name())
                .withTargetUrl(goodsDetail.getData().getShare_url())
                .withMedia(new UMImage(context, goodsDetail.getData().getImg_thumb()))
                .open();*/


         /*   // 整个平台的Controller,负责管理整个SDK的配置、操作等处理
            mController = UMServiceFactory.getUMSocialService("com.umeng.share");

            // 添加QQ、QZone平台
            addQQQZonePlatform();
            // 添加微信、微信朋友圈平台
            addWXPlatform();
            mController.getConfig().setPlatforms(SHARE_MEDIA.WEIXIN,
                    SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ,
                    SHARE_MEDIA.SINA);
            mController.openShare(ProductInfoActivity.this, false);

        setShareContent();*/
        showShare();
    }

    private void showShare() {
        if (null != goodsDetail.getData().getShare_url() && null != goodsDetail.getData().getImg_thumb()) {
            MyShareUtils.showShare(goodsDetail.getData().getGoods_name(),
                    tv_price.getText().toString(),
                    goodsDetail.getData().getShare_url(),
                    goodsDetail.getData().getImg_thumb()
            );

        } else {
            ToastUtils.showToast("商品暂时无法分享");
        }
    }

    GoodsDetailResponseBean goodsDetail;
    GoodsDetailBaseResponseBean.DataBean goodsDetailData;

    TabLayout mTabLayout;
    BanViewPager mViewPager;

    //商品详情标签
    private void initViewPager(GoodsDetailResponseBean result) {
        mTabLayout = (TabLayout) findViewById(R.id.tay_home_tab_view);
        mViewPager = (BanViewPager) findViewById(R.id.tay_home_pager_view);
//        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        setDetailData(result);
        PagerAdapter mAdapter = new PagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(3);
        mTabLayout.setupWithViewPager(mViewPager); //将TabLayout和ViewPager关联起来
    }

    //获取商品详情fragment
    public void setDetailData(GoodsDetailResponseBean result) {

        if (null != result.getData().getTab_info()) {
            List<GoodsDetailResponseBean.DataBean.TabInfoBean> tabinfo = result.getData().getTab_info();
            mTitleList = new ArrayList<>();
            fragmentList = new ArrayList<>();
            for (int i = 0; i < tabinfo.size(); i++) {
                //tab标签
                mTitleList.add(tabinfo.get(i).getName());
                mTabLayout.addTab(mTabLayout.newTab().setText(tabinfo.get(i).getName()));
                //fragment
                fragment = new FastGoodsDetailFragment();
                Bundle bundle = new Bundle();
                bundle.putString("type", tabinfo.get(i).getUrl());
                fragment.setArguments(bundle);
                fragmentList.add(fragment);
            }
        } else {
            return;
        }
    }

    public class PagerAdapter extends FragmentStatePagerAdapter {


        public PagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mTitleList.size();
        }

        //用来设置tab的标题
        @Override
        public CharSequence getPageTitle(int position) {
            return mTitleList.get(position);
        }
    }


    String brand_url;

    private void displayintro(GoodsDetailResponseBean result) {
        if (TextUtils.isEmpty(result.getData().getBrand_url())) {
            iv_infonext.setVisibility(View.GONE);
            tv_introdetail.setVisibility(View.GONE);
        } else {
            brand_url = result.getData().getBrand_url();

        }
        if (null != result.getData().getBrand_info()) {

            if (!TextUtils.isEmpty(result.getData().getBrand_info().getBrand_logo())) {
                XUtils.image(iv_introduce, result.getData().getBrand_info().getBrand_logo()
                        , XUtils.getImageOptionsBuilder().setImageScaleType(ImageView.ScaleType.CENTER).build()
                        , new Callback.CommonCallback<Drawable>() {
                            @Override
                            public void onSuccess(Drawable drawable) {
                                LogUtils.e(TAG, "drawable:" + (drawable == null));
                            }

                            @Override
                            public void onError(Throwable throwable, boolean b) {
                                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv_introduce.getLayoutParams();
                                params.height = 206 * metrics.widthPixels / 1080;
                                iv_introduce.setLayoutParams(params);
//                                iv_introduce.setLayoutParams(new LinearLayout.LayoutParams(550 * metrics.widthPixels / 1080, 367 * metrics.widthPixels / 1080));
                            }

                            @Override
                            public void onCancelled(CancelledException e) {

                            }

                            @Override
                            public void onFinished() {

                            }
                        });
            } else {
//                iv_introduce.setMaxHeight(367 * metrics.widthPixels / 1080);
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv_introduce.getLayoutParams();
                params.height = 206 * metrics.widthPixels / 1080;
                iv_introduce.setLayoutParams(params);
                iv_introduce.setImageResource(R.drawable.placeholder);
            }
            if (!TextUtils.isEmpty(result.getData().getBrand_info().getBrand_desc())) {
                tv_introduce.setText("        " + result.getData().getBrand_info().getBrand_desc());
            }
        }
        if (result.getData().getGoods_album() != null && result.getData().getGoods_album().size() > 0) {
            info_banner.setDatas(result.getData().getGoods_album());
        }
    }

    static Point size;
    static float density;


    private void getGoodsDetailBase(GoodsDetailResponseBean.DataBean data) {
        if (goodsDetailData == null) {
            goodsDetailData = new GoodsDetailBaseResponseBean.DataBean();
        }
        if (data == null) {
            return;
        } else {
        }
        goodsDetailData.setImg_thumb_min(data.getImg_thumb_min());
        goodsDetailData.setGoods_name(data.getGoods_name());
        goodsDetailData.setSub_name(data.getSub_name());
        goodsDetailData.setStock(data.getStock());
        goodsDetailData.setSale_limit(data.getSale_limit());
        goodsDetailData.setPrice(data.getPrice());
        goodsDetailData.setCart_num(data.getCart_num());
        goodsDetailData.setBrand_size(data.getBrand_size());

        LogUtils.e("goodsDetailData:", goodsDetailData.toString());

        getView(activity, R.id.ll_nav_bottom).setClickable(true);
    }

    //商品数据
    private void displayGoodsDetail(GoodsDetailResponseBean.DataBean data) {
        if (data.getIs_collect() == 1) {
            iv_like.setImageResource(R.drawable.ic_loved);
        } else {
            iv_like.setImageResource(R.drawable.ic_love);
        }
        if (!ViewUtils.isEmpty(data.getCart_num()) && !"0".equals(data.getCart_num())) {
//            tv_bag_count.setVisibility(View.VISIBLE);
            tv_bag_count.setText(data.getCart_num());
        } else {
            tv_bag_count.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(data.getBarcode())) {
            tv_code.setText(data.getBarcode());
            if (App.user.getUserType() > 0) {
                tv_code.setVisibility(View.VISIBLE);
            } else {
                tv_code.setVisibility(View.GONE);
            }
        } else {
            tv_code.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(data.getBrand_name())) {
            tv_sub.setText(data.getBrand_name());
        } else {
            tv_sub.setVisibility(View.GONE);
        }
        if (!ViewUtils.isEmpty(data.getGoods_name())) {
            tv_name.setText(data.getGoods_name());
        }
        if (TextUtils.isEmpty(startdate) || TextUtils.isEmpty(enddate)) {
            tv_price.setText("¥ " + data.getPrice());
            tv_market_price.setText(data.getPrice_name() + ":¥ " + data.getMarket_price());
//            tv_market_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            tv_originalPrice.setText("国内参考价:   ¥ " + data.getMarket_price());
            if (!TextUtils.isEmpty(data.getDiscount())) {
//                ll_discount.setVisibility(View.VISIBLE);//折扣
                tv_price_count.setText(data.getDiscount() + "折");
            } else {
                ll_discount.setVisibility(View.GONE);//折扣
            }
        } else if (Long.parseLong(startdate) > 0 || Long.parseLong(enddate) <= 0) {
            //未开始
            rl_time.setVisibility(View.GONE);//计时器
            if (market) {
                ll_discount.setVisibility(View.GONE);
                tv_market_price.setVisibility(View.GONE);
                tv_price.setText("价格：待定");
                tv_price.setTextSize(16);
                tv_originalPrice.setText("国内参考价:   ¥ " + data.getMarket_price() + "");
            } else {
                if (!TextUtils.isEmpty(data.getDiscount())) {
//                    ll_discount.setVisibility(View.VISIBLE);//折扣
                    tv_price_count.setText(data.getDiscount() + "折");
                } else {
                    ll_discount.setVisibility(View.GONE);//折扣
                }
                tv_price.setText("¥ " + data.getPrice() + "");
                tv_market_price.setText(data.getPrice_name() + ":¥ " + data.getMarket_price() + "");
//                tv_market_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                tv_originalPrice.setText("国内参考价:   ¥ " + data.getMarket_price() + "");
            }

        } else if (Long.parseLong(startdate) <= 0 && Long.parseLong(enddate) > 0) {
            rl_time.setVisibility(View.VISIBLE);//计时器
            if (market) {
                ll_discount.setVisibility(View.GONE);
                tv_market_price.setVisibility(View.GONE);
                tv_price.setText("价格：待定");
                tv_price.setTextSize(16);
                tv_market_price.setText(data.getPrice_name() + ":¥ " + data.getMarket_price() + "");
            } else {
                if (!TextUtils.isEmpty(data.getDiscount())) {
//                    ll_discount.setVisibility(View.VISIBLE);//折扣
                    tv_price_count.setText(data.getDiscount() + "折");
                } else {
                    ll_discount.setVisibility(View.GONE);//折扣
                }
                tv_price.setText("¥ " + data.getEvent_price() + "");
                tv_market_price.setText(data.getPrice_name() + ":¥ " + data.getPrice() + "");
//                tv_market_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                tv_originalPrice.setText("国内参考价:   ¥ " + data.getMarket_price() + "");
            }

        }


        if (TextUtils.equals("1", data.getIs_license())) {
            iv_mark.setVisibility(View.GONE);
        } else {
            iv_mark.setVisibility(View.VISIBLE);
        }
    }

    //收藏商品
    private void goodsCollect() {
        GoodsCollectRequestFilter filter = new GoodsCollectRequestFilter(activity);
        filter.requestBean.method = goodsDetail.getData().getIs_collect() == 0 ? "goodsCollect" : "goodsUnCollect";
        filter.requestBean.goods_id = goodsDetail.getData().getId();
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<BaseResponseBean>() {
            @Override
            public void onSuccess(BaseResponseBean result) {
                goodsDetail.getData().setIs_collect(0 == goodsDetail.getData().getIs_collect() ? 1 : 0);
                if (goodsDetail.getData().getIs_collect() == 1)
                    iv_like.setImageResource(R.drawable.ic_loved);
                else iv_like.setImageResource(R.drawable.ic_love);
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                if (failedType != 300)
                    ToastUtils.showToast("操作失败");
            }
        });
    }

    //加入购物车
    private void joinCart() {
        final JoinCartRequestFilter filter = new JoinCartRequestFilter(activity);
        filter.requestBean.gid = product_id;
        filter.requestBean.is_pay = navIndex == 0 ? 0 : 1;
        filter.requestBean.number = String.valueOf(count);
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<BaseResponseBean>() {
                               @Override
                               public void onSuccess(BaseResponseBean result) {
                                   if (navIndex == 0) {
                                       if (ViewUtils.isEmpty(goodsDetailData.getCart_num()) || "0".equals(goodsDetailData.getCart_num())) {
                                           goodsDetailData.setCart_num("1");
                                       } else {
                                           goodsDetailData.setCart_num(String.valueOf(Integer.parseInt(goodsDetailData.getCart_num()) + 1));
                                       }
//                                       tv_bag_count.setVisibility(View.VISIBLE);
                                       tv_bag_count.setText(goodsDetailData.getCart_num());

                                       ToastUtils.showToast("加入购物车成功");
                                   } else if (navIndex == 1) {
                                       Intent intent = new Intent(activity, OrderFormActivity.class);
                                       startActivity(intent);
                                   }

                                   if (buyDialog != null && buyDialog.isShowing()) buyDialog.hide();
                               }

                               @Override
                               public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                                   LogUtils.e(TAG, serverError != null ? serverError.toString() : failedType);
                                   ToastUtils.showToast(navIndex == 0 ? "加入购物车失败" : (!ViewUtils.isEmpty(serverError.mess) ? serverError.mess : "网络连接不稳定，请稍后再试"));
                               }
                           }

        );
    }

    String product_id;

    /**
     * buy dialog
     */
    Dialog buyDialog;
    View view;
    ImageView iv_buy_image, iv_minus, iv_plus;
    TextView tv_count, tv_buy_name, tv_brandname, tv_market, tv_dis,
            tv_oriprice, tv_buy_price, tv_pay, tv_topay, tv_pay2,tv_buy;
    LinearLayout ll_content, ll_dis;

    int count = 0, storeCount = 0;
    /**
     * 单价
     */
    Double price;

    GoodsDetailUtils goodsDetailUtils;
    LinearLayout myEdite;

    private void initDialog(int type) {//1,我订.2,我拍
        if (buyDialog == null && goodsDetailData != null) {
            view = getLayoutInflater().inflate(R.layout.dialog_buy, null);
            view.setMinimumWidth(getResources().getDisplayMetrics().widthPixels);
            dialog_web_size = ViewUtils.getView(view, R.id.web_size);
            iv_buy_image = ViewUtils.getView(view, R.id.iv_buy_image);
            tv1 = ViewUtils.getView(view, R.id.tv1);
            tv2 = ViewUtils.getView(view, R.id.tv2);
            tv3 = ViewUtils.getView(view, R.id.tv3);
            myEdite = ViewUtils.getView(view, R.id.myEdite);
            editText = ViewUtils.getView(view, R.id.et1);
            tv_buy_name = ViewUtils.getView(view, R.id.tv_name);
            tv_buy_price = ViewUtils.getView(view, R.id.tv_price);
            tv_brandname = ViewUtils.getView(view, R.id.tv_sub);
            tv_dis = ViewUtils.getView(view, R.id.tv_price_count);
            tv_market = ViewUtils.getView(view, R.id.tv_market_price);
            tv_oriprice = ViewUtils.getView(view, R.id.tv_originalPrice);
            iv_minus = ViewUtils.getView(view, R.id.iv_minus);
            iv_plus = ViewUtils.getView(view, R.id.iv_plus);
            tv_count = ViewUtils.getView(view, R.id.tv_count);
            tv_topay = ViewUtils.getView(view, R.id.tv_topay);
            ll_content = ViewUtils.getView(view, R.id.ll_selector);
            tv_pay = (TextView) view.findViewById(R.id.tv_pay);
            tv_pay2 = (TextView) view.findViewById(R.id.tv_pay2);
            ll_dis = ViewUtils.getView(view, R.id.ll_discount);
            ViewUtils.getView(view, R.id.iv_cancel).setOnClickListener(this);
            ViewUtils.getView(view, R.id.iv_minus).setOnClickListener(this);
            ViewUtils.getView(view, R.id.iv_plus).setOnClickListener(this);
            ViewUtils.getView(view, R.id.tv_pay).setOnClickListener(this);
            ViewUtils.getView(view, R.id.tv_pay2).setOnClickListener(this);
            displayGoodsDetailBase();

            goodsDetailUtils = new GoodsDetailUtils(ProductInfoActivity.this);
            goodsDetailUtils.reloadDatas(activity, goodsDetail, ll_content, new GoodsDetailUtils.OnSelectedListener() {
                @Override
                public void onBaseDatasChanged(GoodsDetailBaseResponseBean.DataBean baseResponseBean) {
                    goodsDetailData = baseResponseBean;
                    displayGoodsDetailBase();
                }
            });

            buyDialog = new Dialog(activity, R.style.BuyDialogStyle);
            buyDialog.setContentView(view);
            Window dialogWindow = buyDialog.getWindow();
            dialogWindow.setGravity(Gravity.BOTTOM);
            WindowManager.LayoutParams params = dialogWindow.getAttributes();
            params.x = 0;
            params.y = 0;
            dialogWindow.setAttributes(params);
        }
        tv3.setText(type == 1 ? "我的\n尺码" : "拍价");
        myEdite.setVisibility(View.GONE);
        tv_pay2.setVisibility(View.GONE);
        tv_pay.setClickable(true);
        tv_pay.setTextColor(getResources().getColor(R.color.white));
        if (type == 3) {
            if (TextUtils.equals(goodsDetail.getData().getIs_license(), "0") && App.user != null && App.user.getUserType() != 1) {

                tv_pay.setBackgroundColor(getResources().getColor(R.color.text_introduce));
                tv_pay.setText("该商品仅实体店出售");
                tv_pay.setClickable(false);


            } else {
                if (navIndex == 0) {
                    tv_pay.setText("确定");
                } else if (navIndex == 1) {
                    tv_pay.setText("去付款");
                }
            }
        } else if (type == 1 || type == 2) {
            myEdite.setVisibility(View.VISIBLE);
            if(seconds2<=0 && type==2){
                tv_pay.setClickable(false);
                tv_pay.setTextColor(getResources().getColor(R.color.gray_pressed));
            }
            tv_pay.setText(type == 1 ? "我订" : "我拍");
            tv_pay.setBackgroundColor(getResources().getColor(R.color.black));
        } else if (type == 4) {
            tv_pay.setText("我要试");
//            tv_pay2.setVisibility(View.VISIBLE);
//            tv_pay2.setText("试衣间");
        }
        buyDialog.show();
    }


    View infoView;
    TextView tv_complete, tv1, tv2, tv3;
    EditText editText;
    Dialog dialog_info;
    ListView ls_info;

    public void initInfoDialog() {
        if (dialog_info == null) {
            infoView = getLayoutInflater().inflate(R.layout.dialog_info, null);
            infoView.setMinimumWidth(getResources().getDisplayMetrics().widthPixels);
            tv_complete = ViewUtils.getView(infoView, R.id.tv_complete);
            ls_info = ViewUtils.getView(infoView, R.id.ls_info);
            ls_info.setAdapter(new DialogAdapter());
            tv_complete.setOnClickListener(this);
            dialog_info = new Dialog(activity, R.style.BuyDialogStyle);
            dialog_info.setContentView(infoView);
            Window dialogWindow = dialog_info.getWindow();
            Display display = getWindowManager().getDefaultDisplay();
            WindowManager.LayoutParams lp = dialog_info.getWindow().getAttributes();
            lp.width = (int) (display.getWidth()); //设置宽度
            lp.height = (int) (display.getHeight() * 0.7);
            dialog_info.getWindow().setAttributes(lp);
            dialogWindow.setGravity(Gravity.BOTTOM);
        }

        dialog_info.show();
    }


    private void displayGoodsDetailBase() {
        if (!ViewUtils.isEmpty(goodsDetailData.getImg_thumb_min()))
            XUtils.image(iv_buy_image, goodsDetailData.getImg_thumb_min());
        if (!ViewUtils.isEmpty(goodsDetailData.getGoods_name()))
            tv_buy_name.setText(goodsDetailData.getGoods_name());
        if (!ViewUtils.isEmpty(data.getBrand_name())) {
            tv_brandname.setText(data.getBrand_name());
        }
        tv1.setText("发售时间:" + data.getSale_date());
        if (TextUtils.isEmpty(data.getEvent_start_date()) || TextUtils.isEmpty(data.getEvent_end_date())) {
            tv_buy_price.setText("¥ " + data.getPrice());
            tv_market.setText(data.getMarket_price());
            tv_market.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            tv_oriprice.setText("国内参考价:    ¥" + data.getMarket_price());
            if (!TextUtils.isEmpty(data.getDiscount())) {
                ll_dis.setVisibility(View.VISIBLE);//折扣
                tv_dis.setText(data.getDiscount() + "折");
            } else {
                ll_dis.setVisibility(View.GONE);//折扣
            }
        } else if (Long.parseLong(data.getEvent_start_date()) > 0 || Long.parseLong(data.getEvent_end_date()) <= 0) {
            //未开始
            if (market) {
                ll_dis.setVisibility(View.GONE);
                tv_market.setVisibility(View.GONE);
                tv_buy_price.setText("价格：待定");
                tv_price.setTextSize(16);
                tv_oriprice.setText("国内参考价:    ¥" + data.getMarket_price() + "");
            } else {
                if (!TextUtils.isEmpty(data.getDiscount())) {
                    ll_dis.setVisibility(View.VISIBLE);//折扣
                    tv_dis.setText(data.getDiscount() + "折");
                } else {
                    ll_dis.setVisibility(View.GONE);//折扣
                }
                tv_buy_price.setText("¥ " + data.getPrice() + "");
                tv_market.setText(data.getMarket_price() + "");
                tv_market.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                tv_oriprice.setText("国内参考价:    ¥" + data.getMarket_price() + "");
            }

        } else if (Long.parseLong(data.getEvent_start_date()) <= 0 && Long.parseLong(data.getEvent_end_date()) > 0) {
            if (market) {
                ll_dis.setVisibility(View.GONE);
                tv_market.setVisibility(View.GONE);
                tv_buy_price.setText("价格：待定");
                tv_price.setTextSize(16);
                tv_market.setText(data.getMarket_price() + "");
            } else {
                if (!TextUtils.isEmpty(data.getDiscount())) {
                    ll_dis.setVisibility(View.VISIBLE);//折扣
                    tv_dis.setText(data.getDiscount() + "折");
                } else {
                    ll_dis.setVisibility(View.GONE);//折扣
                }
                tv_buy_price.setText("¥ " + data.getEvent_price() + "");
                tv_market.setText(data.getPrice() + "");
                tv_market.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                tv_oriprice.setText("国内参考价:    ¥" + data.getMarket_price() + "");
            }

        }

//        if (!ViewUtils.isEmpty(goodsDetailData.getPrice()))
//            tv_buy_price.setText("¥ " + goodsDetailData.getPrice());
        if (!ViewUtils.isEmpty(goodsDetailData.getStock())) {
//            tv_buy_stock.setText("库存 " + goodsDetailData.getStock() + "件 ");

            if (TextUtils.equals("0", goodsDetailData.getSale_limit()))
                storeCount = Integer.parseInt(goodsDetailData.getStock());
            else
                storeCount = Math.min(Integer.parseInt(goodsDetailData.getStock()), Integer.parseInt(goodsDetailData.getSale_limit()));
        }
        if (!ViewUtils.isEmpty(goodsDetailData.getBrand_size())) {
            dialog_web_size.getSettings().setJavaScriptEnabled(true);
            dialog_web_size.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
            dialog_web_size.setWebChromeClient(new WebChromeClient());
            dialog_web_size.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
            LogUtils.e("goodsDetailData.getBrand_size()", goodsDetailData.getBrand_size());
            dialog_web_size.loadDataWithBaseURL(null, goodsDetailData.getBrand_size(), "text/html", "utf-8", null);
            dialog_web_size.scrollTo(0, 0);
        }
        if (!ViewUtils.isEmpty(goodsDetailData.getCart_num()) && !"0".equals(goodsDetailData.getCart_num())) {
//            tv_bag_count.setVisibility(View.VISIBLE);
            tv_bag_count.setText(goodsDetailData.getCart_num());
        } else tv_bag_count.setVisibility(View.GONE);

        if (storeCount > 0)
            count = 1;
        else count = 0;
        price = Double.parseDouble(goodsDetailData.getPrice());

        displayBuyCountAndPrice();
    }

    private void displayBuyCountAndPrice() {
        tv_count.setText(String.valueOf(count));
        if (count > 1) iv_minus.setImageResource(R.drawable.minus);
        else iv_minus.setImageResource(R.drawable.minus_grey);
        if (count >= storeCount) iv_plus.setImageResource(R.drawable.plus_grey);
        else iv_plus.setImageResource(R.drawable.plus);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

       /* UMSsoHandler ssoHandler = mController.getConfig().getSsoHandler(
                resultCode);
        if (ssoHandler != null) {
            ssoHandler.authorizeCallBack(requestCode, resultCode, data);
        }*/
    }


    public class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return tips.size();
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = getLayoutInflater().from(ProductInfoActivity.this).inflate(R.layout.item_list_post, null);
                holder.title = (TextView) convertView.findViewById(R.id.tv_post);
                holder.info = (TextView) convertView.findViewById(R.id.tv_desc);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.title.setText((String) tips.get(position).getName());
            holder.info.setText((String) tips.get(position).getDesc());

            return convertView;
        }

        class ViewHolder {
            public TextView title;
            public TextView info;
        }

    }


    public class DialogAdapter extends BaseAdapter {

        @Override
        public int getCount() {

            return tips.size();
        }

        @Override
        public Object getItem(int position) {

            return position;
        }

        @Override
        public long getItemId(int position) {

            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;

            if (convertView == null) {
                holder = new ViewHolder();
                convertView = getLayoutInflater().from(ProductInfoActivity.this).inflate(R.layout.item_dialoginfo, null);
                holder.title = (TextView) convertView.findViewById(R.id.tv_title);
                holder.name = (TextView) convertView.findViewById(R.id.tv_name);
                holder.desc = (TextView) convertView.findViewById(R.id.tv_desc);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.title.setText(tips.get(position).getName().substring(0, 2));
            holder.name.setText(tips.get(position).getName());
            holder.desc.setText(tips.get(position).getDesc());
            return convertView;
        }

        class ViewHolder {
            public TextView title, name;
            public TextView desc;
        }

    }
}
